var UI = {};
$(document).ready(
    function(){
        
        (function (UI) {
            
            UI.start = function(){
                $.when(Actions.barStatsHighestRated({action : "test"})).then(
                    function(data){
                        var ratedBars = [];
                        
                        for(var i=0; i<data.length; i++){
                            ratedBars.push([data[i].name, Number(data[i].rating)]);
                        }
                        $('#chart-highest-rated').highcharts({
                            chart: {
                                type: 'column',
                                backgroundColor:'rgba(255, 255, 255, 0.1)',
                            },
                            title: {
                                text: 'Highest rated bars'
                            },
                            subtitle: {
                                text: 'Top 5'
                            },
                            xAxis: {
                                type: 'category',
                                labels: {
                                    rotation: -45,
                                    style: {
                                        fontSize: '13px',
                                        fontFamily: 'Verdana, sans-serif'
                                    }
                                }
                            },
                            yAxis: {
                                min: 0,
                                title: {
                                    text: 'Rating'
                                }
                            },
                            legend: {
                                enabled: false
                            },
                            tooltip: {
                                pointFormat: 'Average Rating: <b>{point.y:.1f}</b>'
                            },
                            series: [{
                                name: 'Rating',
                                data: ratedBars,
                                dataLabels: {
                                    enabled: true,
                                    rotation: -90,
                                    color: '#FFFFFF',
                                    align: 'right',
                                    x: 4,
                                    y: 10,
                                    style: {
                                        fontSize: '13px',
                                        fontFamily: 'Verdana, sans-serif',
                                        textShadow: '0 0 3px black'
                                    }
                                }
                            }]
                        });
                    }
                );
            };
            
        }(UI));
        var Helpers = {};
        (function (Helpers) {
            
            
            
        }(Helpers));
        
        var Actions = {};
        (function (Actions) {
                        
            Actions.barStatsHighestRated = function(args) {
                var dfd = new $.Deferred();
                $.ajax({
                    type: "GET",
                    url: "../resources/helpers/barStatsHighestRated.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        data = JSON.parse(data);
                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
        }(Actions));
        
        var Controller = {};
        (function (Controller) {
            
            Controller.init= function(){
                
            };
            
        }(Controller));	
        
        UI.start();
        Controller.init();
    }
);